package org.brakepedal.server.pojo;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import javax.bluetooth.RemoteDevice;
import java.io.IOException;

/**
 * Date: 2024/4/1 13:10
 *
 * @author Huanyu Mark
 */
public class BtInfo implements Vo {
    @Getter
    @Setter
    @JsonProperty
    private String name;

    @Getter
    @Setter
    @JsonProperty
    private String address;

    @Getter
    @Setter
    @JsonIgnore
    private RemoteDevice pairableDevice;

    public BtInfo(RemoteDevice pairableDevice) throws IOException {
        this.pairableDevice = pairableDevice;
        this.name = pairableDevice.getFriendlyName(false);
        this.address = pairableDevice.getBluetoothAddress();
    }

    @JsonCreator
    public BtInfo() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof BtInfo btInfo)) return false;

        if (!getName().equals(btInfo.getName())) return false;
        return getAddress().equals(btInfo.getAddress());
    }

    @Override
    public int hashCode() {
        int result = getName().hashCode();
        result = 31 * result + getAddress().hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "BtInfo{" +
                "name='" + name + '\'' +
                ", address='" + address + '\'' +
                '}';
    }
}
